def is_prime(n):

    for i in range(2, int(n**0.5)+1):

        if n % i == 0:

            return False

    return True



digits = {

    "zero": "0",

    "one": "1",

    "two": "2",

    "three": "3",

    "four": "4",

    "five": "5",

    "six": "6",

    "seven": "7",

    "eight": "8",

    "nine": "9",

}



s = input()

lst = s.split()

num = ""

for word in lst:

    if word in digits:

        num += digits[word]

    else:

        print("Wrong input")

        exit()



num = int(num)



small = None

big = None



for n in range(num, num + 10000):

    if is_prime(n):

        big = n

        break



for n in range(num, 2, -1):

    if is_prime(n):

        small = n

        break





if big is None:

    print(small)

elif small is None:

    print(big)

elif big - num >= num - small:

    print(small)

else:

    print(big)

